#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int, int> mypair;
const int maxn=500, maxm=500, maxk=500;
int n, m, k, c[maxk+1], cnt[maxk+1];
bool now[maxm+1];

struct Graph {
	int n, m, ind[maxm+1], to[maxm*maxm+1], link[maxm*maxm+1], dis[maxm+1], from[maxm+1];
	bool sf[maxm+1], ef[maxm+1];

	void init(int size) {
		n=size, m=0;
		memset(ind+1, 0, sizeof(int)*n);
		memset(sf+1, 0, sizeof(bool)*n);
		memset(ef+1, 0, sizeof(bool)*n);
	}

	void addSide(int u, int v) {
		m++;
		to[m] = v;
		link[m] = ind[u];
		ind[u] = m;
	}

	int run() {
		static priority_queue<mypair, vector<mypair>, greater<mypair> > heap;
		for (int i=1; i<=n; i++) {
			if (sf[i]) {
				dis[i] = 0;
				heap.push(mypair(dis[i], i));
			} else {
				dis[i] = m+1;
			}
		}

		for (; !heap.empty(); ) {
			int o=heap.top().second;
			heap.pop();
			for (int i=ind[o]; i; i=link[i]) {
				if (dis[to[i]]>dis[o]+1) {
					dis[to[i]] = dis[o]+1;
					from[to[i]] = o;
					heap.push(mypair(dis[to[i]], to[i]));
				}
			}
		}

		dis[0] = m+1;
		int ret=0;
		for (int i=1; i<=n; i++) {
			if (ef[i] && dis[i]<dis[ret]) ret=i;
		}
		return ret;
	}
} g;

struct Set {
	int fa[maxn+1];

	void init(int n) {
		for (int i=1; i<=n; i++) fa[i] = i;
	}

	int getFa(int o) {
		return fa[o]==o ? o : fa[o]=getFa(fa[o]);
	}

	void merge(int u, int v) {
		u=getFa(u), v=getFa(v);
		if (u!=v) fa[u]=v;
	}
} set;

struct Edge { int u, v, w; } e[maxm+1];

int main() {
	freopen("forget.in", "r", stdin);
	freopen("forget.out", "w", stdout);

	scanf("%d %d %d", &n, &m, &k);
	for (int i=1; i<=k; i++) scanf("%d", c+i);
	for (int i=1; i<=m; i++) {
		scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w);
	}

	for (int i=1; i<n; i++) {
		g.init(m);
		for (int o=1; o<=m; o++) {
			if (now[o]) {
				set.init(n);
				for (int j=1; j<=m; j++) {
					if (now[j] && j!=o) set.merge(e[j].u, e[j].v);
				}
				for (int x=1; x<=m; x++) {
					if (!now[x] && set.getFa(e[x].u)!=set.getFa(e[x].v)) {
						g.addSide(o, x);
					}
				}
			} else {
				for (int x=1; x<=m; x++) {
					if (now[x] && (e[x].w==e[o].w || cnt[e[o].w]<c[e[o].w])) {
						g.addSide(o, x);
					}
				}
			}
		}

		set.init(n);
		for (int o=1; o<=m; o++) {
			if (now[o]) set.merge(e[o].u, e[o].v);
		}
		for (int o=1; o<=m; o++) {
			if (!now[o] && set.getFa(e[o].u)!=set.getFa(e[o].v)) {
				g.sf[o] = true;
			}
			if (!now[o] && cnt[e[o].w]<c[e[o].w]) {
				g.ef[o] = true;
			}
		}

		int t=g.run();
		if (t) {
			for (int i=t; i; i=g.from[i]) {
				cnt[e[i].w] += now[i] ? -1 : 1;
				now[i] = !now[i];
			}
		} else break;
	}

	int ans=0;
	for (int i=1; i<=m; i++) ans+=now[i];
	printf("%d\n", m-ans);
	for (int i=1; i<=m; i++) {
		if (!now[i]) printf("%d ", i);
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}
